package com.zhouzj.blog.controller;

import com.zhouzj.blog.entity.Article;
import com.zhouzj.blog.repo.ArticleRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * ArticleController
 *
 * @author zhouzhijun
 * @since 2021/3/12
 **/
@Controller
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleRepository articleRepository;

    @GetMapping
    public String index(Model model, @RequestParam(value = "pageNum", defaultValue = "0") int pageNum,
                        @RequestParam(value = "pageSize", defaultValue = "3") int pageSize){
        Pageable page = PageRequest.of(pageNum,pageSize);
        Page<Article> articlePage = articleRepository.findAll(page);
        model.addAttribute("articlePage", articlePage);
        return "client/index";
    }
}
